package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import easier.app.x.CommonCode;

public class MainActivity109 extends AppCompatActivity {

    private Button button1;
    private Button button2;
    private Button button3;
    private Button button4;
    private Ringtone mRingtone;
    private Button button5;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity109.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main109 );
        initView();
    }

    private void initView() {

        button1 = (Button) findViewById( R.id.button1 );
        button2 = (Button) findViewById( R.id.button2 );
        button3 = (Button) findViewById( R.id.button3 );
        button4 = (Button) findViewById( R.id.button4 );

        button1.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                CommonCode.playRingNotification( v.getContext() );
            }
        } );

        button2.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                CommonCode.playRingAlarm( v.getContext() );
            }
        } );

        button3.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                if ( mRingtone != null && mRingtone.isPlaying() ) {
                    mRingtone.stop();
                    mRingtone = null;
                    return;
                }
                mRingtone = CommonCode.playRingTone( v.getContext() );
            }
        } );

        button4.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                CommonCode.playVibrate( v.getContext() );
            }
        } );

        button5 = (Button) findViewById( R.id.button5 );
        button5.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                CommonCode.playRingFromRaw( v.getContext(), "outgoing_call_ring.mp3" );
            }
        } );
    }
}